package com.hualude.roadsign.controller;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.DTResponseDto;
import com.hualude.roadsign.dto.JsonMsgDto;
import com.hualude.roadsign.dto.SignalLampDto;
import com.hualude.roadsign.service.SignalLampManageService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by xu_jiaHui on 2017/8/2.
 */
@Controller
@RequestMapping("/rds_signalLampManage")
public class SignalLampManageController {
    @Resource
    private SignalLampManageService signalLampManageService;

    @RequestMapping(value = "/getSignalLamp4DT")
    @ResponseBody
    public DTResponseDto getSignalLamp4DT(DTRequestDto dtRequestDto,
                                          String actorIds,
                                          Integer orgId,
                                          Boolean audit,
                                          String startRoad,
                                          String endRoad,
                                          Integer alarmBinding) throws Exception {
        DTResponseDto dtResponseDto = new DTResponseDto();
        try {
            dtResponseDto = signalLampManageService.getSignalLamp4DT(
                    dtRequestDto, actorIds, orgId, audit, startRoad, endRoad, alarmBinding);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }

    @RequestMapping("/getStartRoad")
    @ResponseBody
    public JsonMsgDto getStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.getStartRoad(roadName, actorId, orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping(value = "/getSignalLamp4APP")
    @ResponseBody
    public JsonMsgDto getSignalLamp4APP(String actorIds,
                                        Integer orgId,
                                        Integer mCount,
                                        Integer mSize,
                                        String city,
                                        String startRoad,
                                        String endRoad,
                                        String alarmType) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.getSignalLamp4APP(
                    actorIds, orgId, mCount, mSize, city, startRoad, endRoad, alarmType));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSignalLampById")
    @ResponseBody
    public JsonMsgDto getSignalLampById(Integer signalLampById) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.getSignalLampById(signalLampById));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad(String roadName, Integer actorId, Integer orgId) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.getSectionByStartRoad(roadName, actorId, orgId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("deleteSignalLamp")
    @ResponseBody
    public JsonMsgDto deleteSignalLamp(String signalLampIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.deleteSignalLamp(signalLampIds));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("addSignalLamp")
    @ResponseBody
    public JsonMsgDto addSignalLamp(SignalLampDto signalLampDto) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.addSignalLamp(signalLampDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("updateSignalLamp")
    @ResponseBody
    public JsonMsgDto updateSignalLamp(SignalLampDto signalLampDto) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.updateSignalLamp(signalLampDto));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getCity4SignalLamp")
    @ResponseBody
    public JsonMsgDto getCity4SignalLamp(Integer actorId, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.getCity4SignalLamp(actorId, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getStartRoadByCity")
    @ResponseBody
    public JsonMsgDto getStartRoadByCity(String city, Integer actorId, Integer orgId, Integer mCount, Integer mSize) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.getStartRoadByCity(city, actorId, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSignalLamp4Map4App")
    @ResponseBody
    public JsonMsgDto getSignalLamp4Map4App(Integer orgId,
                                            String actorIds,
                                            double neLongitude,
                                            double neLatitude,
                                            double swLongitude,
                                            double swLatitude) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.getSignalLamp4Map4App
                    (orgId, actorIds, neLongitude, neLatitude, swLongitude, swLatitude));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/getSectionByStartRoad4App")
    @ResponseBody
    public JsonMsgDto getSectionByStartRoad4App(String roadName, String city, Integer actorId, Integer orgId, Integer mCount, Integer mSize) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.getSectionByStartRoad4App(roadName, city, actorId, orgId, mCount, mSize));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setJsonData(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @RequestMapping("/auditSignalLamp")
    @ResponseBody
    public JsonMsgDto auditSignalLamp(String signalLampIds) throws Exception {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setIsSuccess(true);
            jsonMsgDto.setJsonData(signalLampManageService.auditSignalLamp(signalLampIds));
        } catch (Exception e) {
            e.printStackTrace();
            jsonMsgDto.setIsSuccess(false);
        }
        return jsonMsgDto;
    }

    /**
     * @Description:
     * @Author: WYX.
     * @Date: 2018/4/30 22:38.
     */

    @ResponseBody
    @RequestMapping("/bindingDevice")
    public JsonMsgDto bindingDevice(String deviceId, Integer signalLampId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.bindingDevice(deviceId, signalLampId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/unbindingDevice")
    public JsonMsgDto unbindingDevice(String deviceId, Integer signalLampId) {
        JsonMsgDto jsonMsgDto = new JsonMsgDto();
        try {
            jsonMsgDto.setJsonData(signalLampManageService.unbindingDevice(deviceId, signalLampId));
            jsonMsgDto.setIsSuccess(true);
        } catch (Exception e) {
            jsonMsgDto.setIsSuccess(false);
            e.printStackTrace();
        }
        return jsonMsgDto;
    }

    @ResponseBody
    @RequestMapping("/showAlarmHistory")
    public DTResponseDto showAlarmHistory(DTRequestDto dtRequestDto, String deviceId, Integer deviceType) {
        DTResponseDto dtResponseDto = null;
        try {
            dtResponseDto = signalLampManageService.showAlarmHistory(dtRequestDto, deviceId, deviceType);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return dtResponseDto;
    }
}
